package com.bdi.mqtt_broker.main;

import com.bdi.mqtt_broker.server.BrokerServer;
import io.netty.channel.Channel;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author WangNing yogehaoren@gmial.com <br>
 * @since 1.0
 */
@ComponentScan("com.bdi.mqtt_broker")
@Configuration
public class BrokerMain {

    public static ApplicationContext globalContext = null;

    private static final String banner
          = " __          __   _____ _                       _____ ____ _______          \n" +
            " \\ \\        / /  / ____| |                     |_   _/ __ \\__   __|      \n" +
            "  \\ \\  /\\  / /__| (___ | |__   __ _ _ __ ___     | || |  | | | |         \n" +
            "   \\ \\/  \\/ / _ \\\\___ \\| '_ \\ / _` | '__/ _ \\    | || |  | | | |    \n" +
            "    \\  /\\  /  __/____) | | | | (_| | | |  __/   _| || |__| | | |          \n" +
            "     \\/  \\/ \\___|_____/|_| |_|\\__,_|_|  \\___|  |_____\\____/  |_|      \n" +
            "                                                                            \n" +
            "                                                                                ";

    public static void printBanner(){
        System.out.println(banner);
    }

    public static void main(String[] args) throws Exception {

        printBanner();
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(BrokerMain.class);
        globalContext = context;
        BrokerServer server = context.getBean(BrokerServer.class);
        Channel serverChannel = server.start();
        serverChannel.closeFuture().sync();

    }
}
